package main

import "log"

func main() {
	//testChannel01()
	testChannel02()
}

func testChannel01() {
	var ch chan int = make(chan int, 10)
	for i := 0; i < 10; i++ {
		//send 和 recv 都可以作为 select 语句的 case clause
		select {
		case ch <- i:
			log.Println("send", i)
		case v := <-ch:
			log.Println("receive", v)
		}
	}
}
func testChannel02() {
	ch := make(chan int, 10)

	for i := 0; i < 10; i++ {
		ch <- i
	}
	close(ch)
	for v := range ch {
		log.Println("receive", v)
	}

	//或者是忽略读取的值，只是清空 happensBeforeChan：
	//for range ch {
	//}
}
